package com.chanricle.mixtoolset.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;

import com.chanricle.mixtoolset.R;
import com.chanricle.mixtoolset.adapter.MainContentButtonAdapter;
import com.chanricle.mixtoolset.param.ModuleGroup;

/**
 * Main interface, contain a title bar and grid view, contained some button.
 * @author Chanricle King
 *
 */
public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        /*
         * Display the content button by a grid view
         */
        GridView mainContentGridView = (GridView) findViewById(R.id.mainContentGridView);
        
        mainContentGridView.setAdapter(new MainContentButtonAdapter(this));
        
        /*
         * Grid view button click event
         */
        mainContentGridView.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
				Log.d("chanricle debug", "Now, grid view item clicked! Item position is: " + position);
				
				int moduleId = ModuleGroup.modules.keyAt(position);
				
				switch (moduleId) {
				case R.drawable.icon_exchange_rate:
					// TODO Turn to exchange rate module page
					break;
				
				case R.drawable.icon_express_search:
					Intent expressSearchIntent = new Intent(MainActivity.this, ExpressSearchActivity.class);
					startActivity(expressSearchIntent);
					break;
					
				default:
					break;
				}
				
			}
		});
        
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    
}
